/**
 * 检查密码强度
 */
function _checkPassword(field, rules, i, options) {
    var pwd = field.val();

    if (!pwd || pwd.length === 0) {
        return;
    }
    var result = checkPassword(pwd);
    console.log(result);
    if (parseInt(result) < 3) {
        return "密码强度过低";
    }
}

//检查电话
function checkPhone(phone) {
    return /^1[34578]\d{9}$/.test(phone);
}


var timeWait = 60;
var $sendMsgButton = $('.yzm_btn');
var $sendMsg = $(".yzm_time");
var sendOk = "校验码已发送至你的手机，请查收";


//发送验证码
$sendMsgButton.on("click", function () {

    var _this = $('input[name="mobile"]');
    var tel = _this.val();
    if (tel === "" || timeWait !== 60) {
        layer.msg("格式不对");
        return;
    }
    if (!checkPhone(tel)) {
        layer.msg("电话格式不对");
        return;
    }
    var sendType = _this.data('type');
    $.post("message/sendMsg", {tel: tel, type: sendType}, function (data) {
        if (data.code === 200) {
            //执行倒计时
            $sendMsg.show();
            $(".sendBack").html(sendOk);
            time();
        } else {
            layer.msg(data.msg);
        }
    });
});

function time() {
    if (timeWait === 0) {
        $sendMsgButton.prop("disabled", false);
        //timeWait + "秒后，重新发送"
        $sendMsg.html("");
        $sendMsg.hide();
        timeWait = 60;
    } else {
        $sendMsgButton.prop("disabled", true);
        $sendMsg.html("重发验证码(" + timeWait + " s)");
        timeWait--;
        setTimeout(function () {
            time()
        }, 1000)
    }
}